from sqlalchemy import CHAR, Float, Index, String, Text, text, Integer, Column
from sqlalchemy.dialects.mysql import DECIMAL

from mooc.db.database import Base


class User(Base):
    __tablename__ = 'ims_goouc_fullexam_user'
    __table_args__ = (
        Index('idx_openid', 'openid'),
        Index('idx_unionid', 'unionid'),
        Index('idx_weid', 'weid'),
        {'comment': '用户信息表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    openid = Column(String(255), nullable=False, comment='用户标识')
    last_login_time = Column(Integer, nullable=False, comment='最近一次登录时间')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    is_band = Column(Integer, nullable=False, server_default=text("'0'"), comment='是否绑定微信 1是0否')
    h5_openid = Column(String(255), nullable=False)
    unionid = Column(String(255), nullable=True)
    nickname = Column(String(255), nullable=True, comment='用户昵称 可保存特殊符号')
    headimg = Column(String(255), nullable=True, comment='用户头像')
    name = Column(String(50), nullable=True, comment='用户姓名')
    phone = Column(String(11), nullable=True, comment='手机号')
    gradeid = Column(Integer, nullable=True, comment='个人信息完善页面 选择年级ID')
    classid = Column(Integer, nullable=True, comment='班级考试 参加班级的ID')
    groupid = Column(Integer, nullable=True, comment='固定人群组考试 群组ID')
    nativeplace = Column(String(255), nullable=True, comment='籍贯')
    province = Column(String(255), nullable=True, comment='省')
    city = Column(String(255), nullable=True, comment='市')
    county = Column(String(255), nullable=True, comment='县')
    ismember = Column(Integer, nullable=True, server_default=text("'2'"), comment='是否是会员  1 是会员 2不是')
    password = Column(String(255), nullable=True, comment='用户登录密码')
    member_endtime = Column(String(255), nullable=True, comment='会员到期时间 ')
    status = Column(Integer, nullable=True, server_default=text("'1'"), comment='是否拉黑 ')
    integral = Column(Integer, nullable=True, server_default=text("'0'"), comment='用户积分数')
    balance = Column(DECIMAL(8, 2), nullable=True, server_default=text("'0.00'"), comment='用户余额')
    qrcode = Column(String(255), nullable=True, comment='用户二维码路径')
    pid = Column(Integer, nullable=True, server_default=text("'0'"),
                 comment='用户自己注册 为0  扫描其他人二维码 为二维码人的ID')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='是否删除的标识')
    id_card = Column(String(255), nullable=True, comment='身份证号')
    student_id = Column(String(200), nullable=True, comment='学号')
    school = Column(String(255), nullable=True, comment='学校')
    level = Column(Integer, nullable=True, server_default=text("'0'"), comment='用户等级')
    grade = Column(String(255), nullable=True, comment='年级')
    count_day = Column(Integer, nullable=True, server_default=text("'0'"), comment='累计天数')

    class Config:
        orm_mode = True


class UserCollectionPraction(Base):
    __tablename__ = 'ims_goouc_fullexam_user_collection_praction'
    __table_args__ = (
        Index('idx_test_type', 'test_type'),
        Index('idx_testid', 'testid'),
        Index('idx_uid', 'uid'),
        Index('idx_weid', 'weid'),
        {'comment': '收藏'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    testid = Column(Integer, nullable=False, comment='试题ID')
    test_type = Column(Integer, nullable=False, comment='试题类型')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')
    iscollect = Column(Integer, nullable=True, server_default=text("'2'"))

    class Config:
        orm_mode = True


class UserDoexam(Base):
    __tablename__ = 'ims_goouc_fullexam_user_doexam'
    __table_args__ = (
        Index('idx_examid', 'examid'),
        Index('idx_uid', 'uid'),
        Index('idx_weid', 'weid'),
        {'comment': '用户参加全真考试表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    examid = Column(Integer, nullable=False, comment='已发布的试卷  考试 或练习的ID')
    createtime = Column(Integer, nullable=False, comment='交卷时间')
    recordid = Column(Integer, nullable=False, comment='考试记录id')
    evaluation = Column(Integer, nullable=False, server_default=text("'2'"), comment='1已评2未评默认2 3批改中')
    franction = Column(Integer, nullable=True, server_default=text("'0'"), comment='得分情况')
    usetime = Column(String(20), nullable=True, server_default=text("'0'"), comment='考试用时')
    level = Column(String(255), nullable=True)
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserDootherExam(Base):
    __tablename__ = 'ims_goouc_fullexam_user_doother_exam'
    __table_args__ = (
        Index('idx_uid', 'uid'),
        Index('idx_weid', 'weid'),
        {'comment': '用户参加其他考试表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    recordid = Column(Integer, nullable=False, comment='区分是哪一次考试')
    createtime = Column(Integer, nullable=False, comment='交卷时间')
    franction = Column(Integer, nullable=True, server_default=text("'0'"), comment='得分情况')
    usetime = Column(String(20), nullable=True, server_default=text("'0'"), comment='考试用时')
    level = Column(String(255), nullable=True)
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')
    type = Column(Integer, nullable=True, comment='类型2-优先未做3-智能考试')

    class Config:
        orm_mode = True


class UserDoOtherExamAnswer(Base):
    __tablename__ = 'ims_goouc_fullexam_user_doother_exam_answer'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '用户其他考试答题记录表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    recordid = Column(Integer, nullable=False, comment='区分是哪一次考试')
    testid = Column(Integer, nullable=False, comment='试题id')
    test_type = Column(Integer, nullable=False, comment='试题类型')
    isright = Column(Integer, nullable=False, comment='是否正确')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    uanswer = Column(Text, nullable=True, comment='用户答案')
    franction = Column(Integer, nullable=True, server_default=text("'0'"), comment='得分情况')
    ischeck = Column(Integer, nullable=True, server_default=text("'1'"), comment='是否批改 默认为已批该')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')
    type = Column(Integer, nullable=True, comment='类型2-优先未做3-智能考试')

    class Config:
        orm_mode = True


class UserExamAnswer(Base):
    __tablename__ = 'ims_goouc_fullexam_user_exam_answer'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '用户参加全真考试表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    examid = Column(Integer, nullable=False, comment='已发布的试卷  考试 或练习的ID')
    testid = Column(Integer, nullable=False, comment='试题id')
    test_type = Column(Integer, nullable=False, comment='试题类型')
    isright = Column(Integer, nullable=False, comment='是否正确')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    comments = Column(Text, nullable=False, comment='简答题评语')
    simple_evaluation = Column(Integer, nullable=True, server_default=text("'2'"), comment='1已批改默认2未3批改中')
    uanswer = Column(Text, nullable=True, comment='用户答案')
    franction = Column(Integer, nullable=True, server_default=text("'0'"), comment='得分情况')
    ischeck = Column(Integer, nullable=True, server_default=text("'1'"), comment='是否批改 默认为已批该')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')
    recordid = Column(Integer, nullable=True, comment='考试记录id')
    type = Column(Integer, nullable=True, comment='类型只有1-全真')
    simple_score = Column(Integer, nullable=True, comment='简答题评分')

    class Config:
        orm_mode = True


class UserFormid(Base):
    __tablename__ = 'ims_goouc_fullexam_user_formid'
    __table_args__ = (
        Index('idx_uid', 'uid'),
        Index('idx_weid', 'weid'),
        {'comment': 'formid表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    formid = Column(String(255), nullable=False)
    createtime = Column(Integer, nullable=False, comment='创建时间')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserGift(Base):
    __tablename__ = 'ims_goouc_fullexam_user_gift'
    __table_args__ = (
        Index('idx_uid', 'uid'),
        Index('idx_weid', 'weid')
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False)
    giftid = Column(Integer, nullable=False)
    createtime = Column(Integer, nullable=False)
    status = Column(Integer, nullable=True, server_default=text("'0'"))
    updatetime = Column(Integer, nullable=True)
    consignee_name = Column(String(255), nullable=True, comment='收货人姓名')
    consignee_phone = Column(String(255), nullable=True, comment='收货人电话')
    consignee_address = Column(String(255), nullable=True, comment='收货人地址')

    class Config:
        orm_mode = True


class UserKnowledgeCate(Base):
    __tablename__ = 'ims_goouc_fullexam_user_knowledge_cate'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '用户知识点库'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, server_default=text("'0'"), comment='用户id')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    cate = Column(Integer, nullable=True, server_default=text("'0'"), comment='知识点id')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='是否删除的标识')

    class Config:
        orm_mode = True


class UserMember(Base):
    __tablename__ = 'ims_goouc_fullexam_user_member'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '会员设置表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    createtime = Column(Integer, nullable=False, comment='创建时间')
    status = Column(Integer, nullable=True, server_default=text("'2'"), comment='是否开启购买会员')
    scale = Column(DECIMAL(8, 2), nullable=True, server_default=text("'1.00'"), comment='折扣比例')
    info = Column(Text, nullable=True, comment='详细信息')
    price = Column(DECIMAL(8, 2), nullable=True, server_default=text("'0.00'"), comment='VIP单月价格')
    istui = Column(Integer, nullable=True, server_default=text("'0'"), comment='推荐购买的')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserPool(Base):
    __tablename__ = 'ims_goouc_fullexam_user_pool'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '用户题库'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, server_default=text("'0'"), comment='用户id')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    paperid = Column(Integer, nullable=False, server_default=text("'0'"), comment='试卷id')
    poolid = Column(Integer, nullable=True, server_default=text("'0'"), comment='题库id')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='是否删除的标识')

    class Config:
        orm_mode = True


class UserQhigh(Base):
    __tablename__ = 'ims_goouc_fullexam_user_qhigh'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '记录高频上次退出的题id'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    user_id = Column(Integer, nullable=False, comment='用户ID')
    question_id = Column(Integer, nullable=False, comment='试题ID')
    create_time = Column(Integer, nullable=False, comment='创建时间')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserQintensive(Base):
    __tablename__ = 'ims_goouc_fullexam_user_qintensive'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '记录精编上次退出的题id'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    user_id = Column(Integer, nullable=False, comment='用户ID')
    question_id = Column(Integer, nullable=False, comment='试题ID')
    create_time = Column(Integer, nullable=False, comment='创建时间')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserQtype(Base):
    __tablename__ = 'ims_goouc_fullexam_user_qtype'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '记录题型退出时题下标'}
    )

    id = Column(Integer, primary_key=True, index=True)
    uid = Column(Integer, nullable=False)
    type_id = Column(Integer, nullable=False)
    weid = Column(Integer, nullable=True, server_default=text("'0'"))
    last_id = Column(Integer, nullable=True)
    istatus = Column(Integer, nullable=True, server_default=text("'1'"))
    createtime = Column(Integer, nullable=True, comment='时间')

    class Config:
        orm_mode = True


class UserRead(Base):
    __tablename__ = 'ims_goouc_fullexam_user_read'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '用户阅读公告 文章 活动表'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    noticeid = Column(Integer, nullable=False, comment='公告 活动 文章 ID')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserSpecial(Base):
    __tablename__ = 'ims_goouc_fullexam_user_special'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '记录知识点退出时题下标'}
    )

    id = Column(Integer, primary_key=True, index=True)
    uid = Column(Integer, nullable=False)
    special_id = Column(Integer, nullable=False)
    weid = Column(Integer, nullable=True, server_default=text("'0'"))
    last_id = Column(Integer, nullable=True)
    istatus = Column(Integer, nullable=True, server_default=text("'1'"))
    createtime = Column(Integer, nullable=True, comment='时间')

    class Config:
        orm_mode = True


class UserSpequence(Base):
    __tablename__ = 'ims_goouc_fullexam_user_spequence'
    __table_args__ = (
        Index('idx_weid', 'weid'),
        {'comment': '记录顺序上次退出的下标id'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    user_id = Column(Integer, nullable=False, comment='用户ID')
    question_id = Column(Integer, nullable=False, comment='下标ID，这儿是顺序id')
    create_time = Column(Integer, nullable=False, comment='创建时间')
    lib_id = Column(Integer, nullable=True, comment='题库id')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')

    class Config:
        orm_mode = True


class UserWrongPraction(Base):
    __tablename__ = 'ims_goouc_fullexam_user_wrong_praction'
    __table_args__ = (
        Index('idx_test_type', 'test_type'),
        Index('idx_testid', 'testid'),
        Index('idx_uid', 'uid'),
        Index('idx_weid', 'weid'),
        {'comment': '错题集,错题收藏'}
    )

    id = Column(Integer, primary_key=True, index=True)
    weid = Column(Integer, nullable=False)
    uid = Column(Integer, nullable=False, comment='用户ID')
    testid = Column(Integer, nullable=False, comment='试题ID')
    test_type = Column(Integer, nullable=False, comment='试题类型')
    createtime = Column(Integer, nullable=False, comment='创建时间')
    uanswer = Column(Text, nullable=True, comment='用户答案')
    istatus = Column(Integer, nullable=True, server_default=text("'1'"), comment='删除状态')
    iscollect = Column(Integer, nullable=True, server_default=text("'2'"))

    class Config:
        orm_mode = True


